package com.postracker.web.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
@RequestMapping("/noajax")
public class NoAjax {

	/**
	 * Handles and retrieves the non-AJAX, ordinary Add page
	 */
	@RequestMapping(value = "addPage", method = RequestMethod.GET)
	public String getNonAjaxAddPage() {
		// This will resolve to /WEB-INF/jsp/nonajax-add-page.jsp
		return "noajax/nonajax-add-page";
	}

	@RequestMapping(value = "addOperation", method = RequestMethod.POST)
	public String add(
			@RequestParam(value = "inputNumber1", required = true) Integer inputNumber1,
			@RequestParam(value = "inputNumber2", required = true) Integer inputNumber2,
			Model model) {
		// Delegate to service to do the actual adding
		Integer sum = Integer.valueOf(inputNumber1.intValue()
				+ inputNumber2.intValue());
		// Add to model
		model.addAttribute("sum", sum);
		// This will resolve to /WEB-INF/jsp/nonajax-add-result-page.jsp
		return "noajax/nonajax-add-result-page";
	}
}
